﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace BloxGin.Input
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class InputHelper : Microsoft.Xna.Framework.GameComponent
    {
        KeyboardState curKeyState;
        KeyboardState lastKeyState;
        MouseState curMouseState;
        MouseState lastMouseState;


        public int MouseX
        {
            get
            {
                return curMouseState.X;
            }
        }
        public int MouseY
        {
            get
            {

                return curMouseState.Y;
            }
        }
        public int MouseWheelValue
        {
            get
            {
                return curMouseState.ScrollWheelValue;
            }
        }


        public InputHelper(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {

            base.Update(gameTime);
        }

        public void Begin()
        {
            curKeyState = Keyboard.GetState();
            curMouseState = Mouse.GetState();
        }
        public void End()
        {
            lastKeyState = curKeyState;
            lastMouseState = curMouseState;
        }

        public bool LeftMouseClick()
        {
            return curMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released;
        }
        public bool RightMouseClick()
        {
            return curMouseState.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released;
        }
        public bool IsNewKeyPress(Keys key)
        {
            return curKeyState.IsKeyDown(key) && lastKeyState.IsKeyUp(key);
        }
        public bool IsKeyDown(Keys key)
        {
            return curKeyState.IsKeyDown(key);
        }

    }
}
